home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / texmac.zip / SPELL.SPM < prev    next >
Text File  |  1990-12-31  |  6KB  |  229 lines

  1. LoadSpeller :  ; force the speller into memory
  2.     if stopped {
  3.         if ((0 subchar engine) != 'S') {
  4.             status "\nLoading speller..."
  5.             set Q0 "speller.eng" NeedDisk
  6.             set engine QJ
  7.             }
  8.         }
  9.     0 -> AutoCorrect        ; if speller can't load, force autocorrect off
  10.  
  11. CorrectDoIt :        ; Loadspeller must have been done. Passed the flags!
  12.     -> int correctflags    ; flags for correction
  13.     1-> int result        ; for the result
  14.     if inruler (toeol c 0 return)    ; don't do anything in a ruler
  15.     if ((previous == '^O') || (previous == '^V') || (current = '@')) {
  16.         past istoken
  17.         0 return
  18.         }        ; don't ever lookup formatter words
  19.     if ((current < '0')|| (current > '9')) {
  20.         do {
  21.             correctflags (runengine (past istoken)) -> result
  22.             }
  23.         while (result & 16)
  24.         }
  25.     else (0 -> result)        ; return false if word not checked
  26.     past istoken
  27.     result                ; return result
  28.  
  29. CorrectLastBad :     LoadSpeller
  30.     mark {
  31.         if (BadWordPending > 0) {
  32.             mark {
  33.                 to QE
  34.                 delete past istoken QD
  35.                 del
  36.                 }
  37.             0 r search QD
  38.             58+64 CorrectDoIt
  39.             --BadWordPending
  40.             }
  41.         else (message "\nNo misspelled words have been recorded.")
  42.         }
  43.  
  44. CorrectAllBad :            ; correct each misspelling recorded in QE
  45.     if !BadWordPending message "\nNo misspelled words have been recorded."
  46.     else {
  47.         mark {
  48.             while (BadWordPending>0) (CorrectLastBad $ WordBack)
  49.             message "No more misspelled words recorded."
  50.             }
  51.         set QE ""
  52.         }
  53.  
  54. CorrectFile :     mark {
  55.         r toend
  56.         LoadSpeller
  57.         while (to istoken) {
  58.             status "\nChecking spelling..."
  59.             if ('^O' isin) ('^N' csearch c)    ; don't correct within ^O's
  60.             else if stopped(26+64 CorrectDoIt) (setmark abort)
  61.             }
  62.         message "\nSpell correction complete."
  63.         }
  64.  
  65. CorrectRegionRest :     LoadSpeller
  66.     if istoken (r past istoken)    ; ensure that the current word is included
  67.     while ((to istoken) && beforemark) {
  68.         status "\nChecking spelling..."
  69.         if ('^O' isin) ('^N' csearch c)    ; don't correct within ^O's
  70.         else if stopped (26+64 CorrectDoIt) (set gmark abort)
  71.         }
  72.     message "\nSpell correction complete."
  73.  
  74. CorrectPara :     mark {
  75.         ParagraphFwd
  76.         mark    (ParagraphBack CorrectRegionRest)
  77.         }
  78.  
  79. CorrectRegion :     if select {
  80.         markregion CorrectRegionRest
  81.         Unselect
  82.         }
  83.     else    NoBlock
  84.  
  85. CorrectRest :     LoadSpeller
  86.     mark {
  87.         if istoken r past istoken
  88.         if stopped {
  89.             while to istoken {
  90.                 status "\nChecking spelling..."
  91.                 if ('^O' isin) ('^N' csearch c)
  92.                 else (26+64 CorrectDoIt)
  93.                 }
  94.             draw
  95.             if ask "\nAt end of file. Continue from top? " {
  96.                 r toend
  97.                 while ((to istoken) && beforemark) {
  98.                     status "\nChecking spelling..."
  99.                     if ('^O' isin) ('^N' csearch c)
  100.                     else (26+64 CorrectDoIt)
  101.                     }
  102.                 }
  103.             } {setmark return}
  104.         }
  105.     message "\nSpell correction complete."
  106.  
  107. CorrectSent :     mark {
  108.         SentenceFwd
  109.         mark    (SentenceBack CorrectRegionRest)
  110.         }
  111.  
  112. CorrectWord :     int result 
  113.     LoadSpeller
  114.     mark {
  115.         if !istoken (r to istoken) ; if between words, do prev
  116.         r past istoken
  117.         if !stopped (58+64 CorrectDoIt ->result) {
  118.             result == 1 ? message "\nSpelling is correct"
  119.             }
  120.         }
  121.  
  122. ; set Q0 to contain the name of one of the speller dictionaries
  123. ; 0 = Main 1 = User 
  124. GetDictionary :
  125.     ->int x
  126.     set Q0 QJ     ; get engine params
  127.     mark {
  128.         to Q0
  129.         erase (to iswhite past iswhite)    ; engine name
  130.         if x {    ; get user dict name
  131.             erase (to iswhite past iswhite)
  132.         }
  133.         else    {
  134.             to iswhite erase toend
  135.             }
  136.         r toend while (!isend) ToUpper    ; return in upper case
  137.         erase toend    ; remove extension
  138.         }
  139.  
  140. SetDictionary :    ; 0 = main, 1 = user in Q0
  141.     ->int user
  142.     set Q0 "speller.eng" NeedDisk
  143.     set QD QJ        ; preserve so we can restore if error
  144.     do {
  145.         if user {    ; user dictionary
  146.             10 set Q0 flist "*.LX2"
  147.             if !length Q0 error "No user dictionaries found"
  148.             set Q0 fchange "%.LX2" Q0    ; add extension back
  149.             }
  150.         else {    ; main dictionary
  151.             10 set Q0 flist "*.LX1"
  152.             if !length Q0 error "No main dictionaries found"
  153.             set Q0 fchange "%.LX1" Q0    ; add extension back
  154.             }
  155.         mark {
  156.             to QJ    ; put new file name in
  157.             if user {    ; user dic
  158.                 toend
  159.                 erase (r to iswhite)    ; delete name of old use dict
  160.                 insert Q0                ; put in new name
  161.                 }
  162.             else {    ; main dic
  163.                 to iswhite past iswhite    ; to start of main dict name
  164.                 erase (to iswhite)        ; remove main dict. name
  165.                 insert Q0                ; put in new one
  166.                 }
  167.             }
  168.         if stopped {
  169.             status "\nLoading new dictionary..."
  170.             set engine QJ        ; set new engine parameters
  171.             }
  172.         {
  173.             message "\nDictionary not for spelling correction.  Try again."
  174.             set QJ QD
  175.             }
  176.         else break
  177.     }
  178.  
  179. UnLoadEngine :
  180.     int keyp
  181.     int FileFound
  182.     if WasEngine=2 {            ; Save User dictionary
  183.         if !(2 exist "SPELLER.ENG") { ; speller.eng always in same disk
  184.             set Q1 Q0            ; Store actual request in Q1
  185.             set Q0 "SPELLER.ENG"
  186.             SetQDDiskName
  187.             set Q0 Q1            ; Restore Q0
  188.             do {
  189.                 message "\nInsert your \"" QD "\" disk in drive A and press any key (ESC CANCELS)"
  190.                 KeyGet -> keyp
  191.                 if(keyp == abortkey || keyp = '^[') abort
  192.                 2 exist "SPELLER.ENG" -> FileFound
  193.                 if !FileFound stopped error "That was the wrong disk."
  194.                 else break
  195.                 }
  196.             }
  197.         }
  198.     set engine ""        ; Unload engine
  199.     0->WasEngine        ; Reset engine flag
  200.  
  201. ; Use the following macro to assure that a disk with a needed file is there
  202. NeedDisk : ; Q0 = File to look for
  203.     int FileFound
  204.     int keyp
  205.     if (WasEngine && FloppyDisk) UnLoadEngine    ; Unload before flip disk
  206.     0 QCap
  207.     if (2 exist Q0) return
  208.     if !FloppyDisk { ; User has a hard-disk, file missing error
  209.         mark {
  210.             to QD clear
  211.             insert "The file '"
  212.             insert Q0
  213.             insert "' cannot be found."
  214.             }
  215.         error QD        ; Quit with error
  216.         }
  217.     1 Bell        ; alert user if disk not found
  218.                 ; At this step we are sure user has a floppy disk system
  219.     SetQDDiskName    ; So get the disk label to insert in QD
  220.     do {
  221.         message "\nInsert your \"" QD "\" disk in drive A and press any key (ESC CANCELS)"
  222.         KeyGet -> keyp
  223.         if (keyp == abortkey || keyp = '^[') abort
  224.         2 exist Q0 -> FileFound
  225.         if !FileFound stopped error "That was the wrong disk."
  226.         else break
  227.         }
  228.  
  229.